package com.lbn.monitor.widget.calendar;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.provider.SyncStateContract;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;

import com.free.framework.lib.utils.CustomToast;
import com.lbn.monitor.R;
import com.lbn.monitor.base.AppBaseActivity;
import com.lbn.monitor.util.Constant;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/11/8.
 */

public class CalendarDialog extends AppBaseActivity implements CalendarView.CalendarListener {

    @BindView(R.id.calendar_view)
    CalendarView calendarView;

    private boolean isStart = false;

    private long startTime;
    private long endTime;




    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        //最终方案
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            //5.0 全透明实现
            Window window = getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.TRANSPARENT);
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            //4.4 全透明状态栏
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            //透明导航栏 为了适配有虚拟按键的手机，不要打开这项
            //getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }

        setContentView(R.layout.dialog_fragment_calendar);
        ButterKnife.bind(this);
        calendarView.setCalendarListener(this);
//        ConvenientDialog.makeDialog(this, "请选择开始日期");
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void startTime(long time) {
        startTime = time;
    }

    @Override
    public void endTime(long time) {
        endTime = time;
    }

    @Override
    public void confirm() {
        Intent intent = new Intent();
        intent.putExtra(Constant.CALENDAR_START_TIME, startTime);
        intent.putExtra(Constant.CALENDAR_END_TIME, endTime);
        setResult(RESULT_OK, intent);
        CalendarObserver.clear();
        finish();
    }

    @Override
    public void cancel() {
        CalendarObserver.clear();
        finish();
    }

    @Override
    public void error(String msg) {
        Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onBackPressed() {

    }
}
